import { getCarShowInfo, getCarShows, getCartype, getCompany } from '../api';

const actions = {
  setTabbarActive: ({ commit }, active) => {
    return commit('SET_TABBAR_ACTIVE', active);
  },
  setCurrentIndex: ({ commit }, index) => {
    return commit('SET_CURRENT_INDEX', index);
  },
  getCarShows: async ({ commit, dispatch }) => {
    const resp = await getCarShows();
    if (resp && resp.data.state === '000') {
      await dispatch('getCompany');
      await dispatch('getCartype');
      return commit('GET_CARS', { cars: resp.data.data, url: resp.data.host });
    }
  },
  getCartype: async ({ commit }) => {
    const resp = await getCartype();
    if (resp && resp.data.state === '000') {
      return commit('GET_CAR_TYPE', resp.data.data);
    }
  },
  getCarShowInfo: async ({ commit }, id) => {
    const resp = await getCarShowInfo({id});
    if (resp && resp.data.state === '000') {
      return commit('GET_CAR_INFO', resp.data.data);
    }
  },
  getCompany: async ({ commit }) => {
    const resp = await getCompany();
    if (resp && resp.data.state === '000') {
      return commit('GET_COMPANY_INFO', resp.data.data);
    }
  },
};

export default actions;
